<?php

namespace App\Services;

use stdClass;
/**
 * AuthManager
 *
 * @package App\Manager
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class AuthService
{
    /**
     * 获取用户
     *
     * @return stdClass|null
     */
    public function user(){
        return session('user');
    }

    /**
     * 获取ID
     *
     * @return string
     */
    public function id() : string {
        $user = $this->user();
        return $user->uid;
    }

    /**
     * 检查是否登录
     *
     * @return bool
     */
    public function check() : bool {
        $user = $this->user();
        return $user instanceof stdClass;
    }

    /**
     * 用户登录
     *
     * @param stdClass $user
     */
    public function login(stdClass $user){
        session(['user' => $user]);
    }

    /**
     * 用户登出
     *
     */
    public function logout(){
        session(['user' => null]);
    }
}